import {
  HomeOutlined,
  OrderedListOutlined,
  UnorderedListOutlined,
  SafetyOutlined,
  UserSwitchOutlined,
  CopyOutlined,
  FormOutlined,
  IssuesCloseOutlined,
  AppstoreOutlined,
  CarryOutOutlined,
  DiffOutlined,
  CloudOutlined,
  CheckCircleOutlined,
  StopOutlined
} from '@ant-design/icons'

// 图标映射
const iconList = {
  '/home': <HomeOutlined />,
  '/user-manage': <UserSwitchOutlined />,
  '/user-manage/list': <OrderedListOutlined />,
  '/right-manage': <SafetyOutlined />,
  '/right-manage/role/list': <OrderedListOutlined />,
  '/right-manage/right/list': <UnorderedListOutlined />,
  '/news-manage': <CopyOutlined />,
  '/news-manage/add': <FormOutlined />,
  '/news-manage/draft': <IssuesCloseOutlined />,
  '/news-manage/category': <AppstoreOutlined />,
  '/audit-manage': <CarryOutOutlined />,
  '/audit-manage/audit': <DiffOutlined />,
  '/audit-manage/list': <OrderedListOutlined />,
  '/publish-manage': <CloudOutlined />,
  '/publish-manage/unpublished': <IssuesCloseOutlined />,
  '/publish-manage/published': <CheckCircleOutlined />,
  '/publish-manage/sunset': <StopOutlined />
}
const users = JSON.parse(localStorage.getItem('token'))

//数据处理成antd渲染需要的树级结构并添加label和icon
const arrayToTree = (root, children) => {
  // console.log(root,children);
  return root.map(list => {
    list = { ...list, label: list.title, icon: iconList[list.key], children: [] }
    children.forEach(child => {
      child = { ...child, label: child.title, icon: iconList[child.key], rightid: child.rightId }
      delete child.rightId
      if (child.rightid == list.id && child.pagepermisson === 1) {
        list.children.push(child)
      }
    })
    //如果子集为空数组也会显示级联下拉所以删掉
    if (list.children.length == 0) {
      delete list.children
    }
    return list
  })
}

export {
  arrayToTree
}